package servlet;

import dao.TypeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/updateType")
@MultipartConfig
public class GoodsTypePrepareUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 2L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String TypeID = request.getParameter("goodsTypeID");
		String TypeName = request.getParameter("goodsTypeName");
		String TypeDescription = request.getParameter("goodsTypeDescription");
		TypeDao dao = new TypeDao();
		int ret = dao.updateType(TypeName,TypeDescription,TypeID);
		if(ret == -1) {
			response.sendRedirect("error.jsp");
			return;
		}else {
			request.getSession().setAttribute("successMsg", "修改成功！");
			request.getRequestDispatcher("updateType").forward(request, response);
		}
	}
}
